package com.fxu.framework.core.enums;

import com.fxu.framework.biz.base.Limits;
import lombok.AllArgsConstructor;

/***
 * 带有显示默认status字段字符串枚举
 * @author fangxu
 * @version 1.0.0
 ***/
@AllArgsConstructor
public enum ShowStrStatus implements BaseEnum<String, String> {
    DELETE("DELETE", "删除"),
    HIDE("HIDE", "隐藏"),
    SHOW("SHOW", "显示");

    final String code;
    final String desc;

    @Override
    public String code() {
        return code;
    }

    @Override
    public String desc() {
        return desc;
    }

    public static String desc(String code) {
        ShowStrStatus ret = find(code);
        return ret == null ? null : ret.desc;
    }

    public static ShowStrStatus find(String code) {
        return code == null ? null : BaseEnum.findOne(values(), v -> v.code.equals(code));
    }

    public static boolean is(String limits) {
        ShowStrStatus[] enums = ShowStrStatus.values();
        String[] array = new Limits(limits).getArray();
        for (ShowStrStatus e : enums) {
            if (BaseEnum.findOne(array, v -> v.equals(e.code + Limits.SPLIT_CHILD + e.desc)) == null) {
                return false;
            }
        }
        for (String s : array) {
            if (BaseEnum.findOne(enums, v -> s.equals(v.code + Limits.SPLIT_CHILD + v.desc)) == null) {
                return false;
            }
        }
        return true;
    }
}